/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 38917
 * Date: 2025-04-02
 * Time: 11:15
 */
public class Main {
    public static void main(String[] args) {
        Object lockerA = new Object();
        Object lockerB = new Object();
        Object lockerC = new Object();
        Thread thread1 = new Thread(()->{
            try {
                for (int i = 0; i < 10; i++) {
                    synchronized (lockerA) {
                        Thread.sleep(300);
                        synchronized (lockerB) {
                            System.out.print("A");
                        }
                    }
                }
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        });
        //
        Thread thread2 = new Thread(()->{
            try {
                for (int i = 0; i < 10; i++) {
                    synchronized (lockerB) {
                        Thread.sleep(300);
                        synchronized (lockerC) {
                            System.out.print("B");
                        }
                    }
                }
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        });
        //
        Thread thread3 = new Thread(()->{
            try {
                for (int i = 0; i < 10; i++) {
                    synchronized (lockerC) {
                        Thread.sleep(300);
                        synchronized (lockerA) {
                            System.out.println("C");
                        }
                    }
                }
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        });
        thread1.start();
        thread2.start();
        thread3.start();
    }
}